﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace kwzx
{
    public partial class dbrw : Form
    {
        public dbrw()
        {
            InitializeComponent();
        }

        private void dbrw_Load(object sender, EventArgs e)
        {
            this.v_kwzxrw_user_bmTableAdapter.Fill(this.dataSet1.V_kwzxrw_user_bm);

            string sql = " 1=1 ";
            if (this.radioButton1.Checked == true)
            {
                sql += "and czzt ='手动完成'";
            }
            else
            {
                sql += "and czzt <> '手动完成'";
            }
            this.vkwzxrwuserbmBindingSource.Filter = sql;
             
        }

        private void cxbutton_Click(object sender, EventArgs e)
        {
            string sql = " 1=1 ";
            if (this.textBox1.Text.ToString() != "")
            {
                sql += " and XM like '%" + this.textBox1.Text.ToString() + "%'";
            }
            if (this.radioButton1.Checked == true)
            {
                sql += "and czzt ='手动完成'";
            }
            else
            {
                sql += "and czzt <> '手动完成'";
            }
            this.vkwzxrwuserbmBindingSource.Filter = sql;
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            string sql = " 1=1 ";
            RadioButton rb = sender as RadioButton;
            if (rb.Name == "radioButton1")
            {
                sql += "and czzt ='手动完成'";
            }
            else if (rb.Name == "radioButton2")
            {
                sql += "and czzt <> '手动完成'";
            }
            this.vkwzxrwuserbmBindingSource.Filter = sql;
        }
        
        /// <summary>
        /// 通过“类型”字段判断，弹出对应窗口，进行处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void v_kwzxrw_user_bmDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //未成完状态下进行相应操作
            if (this.radioButton1.Checked == true)
            {
                if (e.RowIndex >= 0)
                {
                    var lx = v_kwzxrw_user_bmDataGridView.Rows[e.RowIndex].Cells[5].Value.ToString();//类型（申请卡-授权-消费-等等）
                    int userid = int.Parse(v_kwzxrw_user_bmDataGridView.Rows[e.RowIndex].Cells[3].Value.ToString());//T_USER表的ID
                    int kwzxrwid = int.Parse(v_kwzxrw_user_bmDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString());//卡务中心任务ID
                    string sbsm = v_kwzxrw_user_bmDataGridView.Rows[e.RowIndex].Cells[24].Value.ToString();//失败说明（插入T_USER表的失败说明）

                    //根据类型进行操作
                    //申请卡为走流程上报的人员信息；授权为东屋申请授权操作。
                    if (lx.Equals("申请卡"))
                    {
                        if (sbsm == "身份证号重")
                        {
                            //用户信息和正式表中信息相同，是否进行更换？
                            int user2id = int.Parse(v_kwzxrw_user_bmDataGridView.Rows[e.RowIndex].Cells[26].Value.ToString());//T_USER2表的ID
                            dbrw_xxbj userbj = new dbrw_xxbj(userid, user2id, kwzxrwid);
                            if (userbj.ShowDialog() == DialogResult.OK)
                            {
                                dbrw_fpkh fpcardnofrm = new dbrw_fpkh(kwzxrwid, userid);
                                fpcardnofrm.ShowDialog();
                                dbrw_Load(sender, e);
                            }
                            else
                            {
                                return;
                            }
                        }
                        else
                        {
                            dbrw_fpkh fpcardnofrm = new dbrw_fpkh(kwzxrwid, userid);
                            fpcardnofrm.ShowDialog();
                            dbrw_Load(sender, e);
                        }
                    }
                    else if (lx.Equals("授权"))
                    {
                        dbrw_dwfk dwfk = new dbrw_dwfk(kwzxrwid, userid);
                        if (dwfk.ShowDialog() == DialogResult.OK)
                        {
                            dbrw_Load(sender, e);
                        }
                        else
                        {
                            return;
                        }
                    }
                    else if (lx.Equals("消费"))
                    {
                    }
                }
            }
        }
    }
}
